package com.jiepos.mpos.inter.websocket.trans;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.transaction.service.LogTransJYLSService;
import com.jiepos.mpos.common.constant.ExceptionConstant;
import com.jiepos.mpos.core.entity.MposResponse;
import com.jiepos.mpos.core.util.GlobalUtils;

/**
 * @ClassName: TransMonitorController
 * @Description: 交易监控控制层
 * @author 孙永
 * @date 2018年1月24日 下午6:01:31
 */
@RequestMapping("/transmonitor")
@Controller
public class TransMonitorController {
	
	private static Logger logger = LoggerFactory.getLogger(TransMonitorController.class);
	
	@Autowired
	private LogTransJYLSService logTransJYLSService;
	
	/**
	 * 监控页面
	 * @return
	 */
	@RequestMapping("/index.do")
	public ModelAndView index(){
		ModelAndView view = new ModelAndView("/common/transMonitor");
		view.addObject("wsurl", GlobalUtils.getConfProperty("ws.transmonitor.url"));
		view.addObject("transList", logTransJYLSService.getLastTenTrans());
		return view;
	}

	/**
	 * 监控交易数据
	 * @param locTransNo
	 * @return
	 */
	@RequestMapping("/show.do")
	@ResponseBody
	public MposResponse transMonitor(String locTransNo){
		logger.info("监控交易本地流水号：{}", locTransNo);
		MposResponse response = new MposResponse();
		try{
			TransMonitor.showTrans(locTransNo);
		}catch(Exception e){
			e.printStackTrace();
			response.setException(ExceptionConstant.ERROR);
		}
		return response;
	}
}
